function shellSort(arr) {
  let len = arr.length
  // 选择希尔排序的原稿增量， 初始间隔是N / 2
  let gap = Math.floor(len / 2)
  while (gap > 0) {
    // 以gap作为间隔，进行分组，分组进行插入排序
    for (let i = gap; i < len; i++) {
      let j = i
      let current = arr[gap]
      while (j > 0 && current < arr[j - gap]) {
        arr[j] = arr[j - gap]
        j -= gap
      }
      arr[j] = current
    }
    // 重新计算gap
    gap = Math.floor(gap / 2)
  }
  return arr
}

const arr = [5, 4, 3, 2, 1]
console.log(shellSort(arr))